export const formatDate = (arg, type = "YYYY-MM-DD h:m:s") => {
  if (arg.toString().length == 10) {
    arg = arg * 1000;
  }
  var date = new Date(arg);
  var year = date.getFullYear(); //获取年
  var mouth =
    date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1; //月
  var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); //日
  var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); //时
  var minute =
    date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); //分
  var second =
    date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); //秒
  var week; //星期
  if (date.getDay() == 0) week = "星期日";
  if (date.getDay() == 1) week = "星期一";
  if (date.getDay() == 2) week = "星期二";
  if (date.getDay() == 3) week = "星期三";
  if (date.getDay() == 4) week = "星期四";
  if (date.getDay() == 5) week = "星期五";
  if (date.getDay() == 6) week = "星期六";
  // 通过 '-' 链接
  if (type == "YYYY-MM-DD h:m:s") {
    return (
      year + "-" + mouth + "-" + day + " " + hour + ":" + minute + ":" + second
    );
  }
  if (type == "YYYY-MM-DD h:m") {
    return year + "-" + mouth + "-" + day + " " + hour + ":" + minute;
  }
  if (type == "YYYY-MM-DD") {
    return year + "-" + mouth + "-" + day;
  }
  if (type == "MM-DD") {
    return mouth + "-" + day;
  }
  if (type == "MM-DD WEEK") {
    return mouth + "-" + day + " " + week;
  }
  // 通过 '/' 链接
  if (type == "YYYY/MM/DD h:m:s") {
    return (
      year + "/" + mouth + "/" + day + " " + hour + ":" + minute + ":" + second
    );
  }
  if (type == "YYYY/MM/DD h:m") {
    return year + "/" + mouth + "/" + day + " " + hour + ":" + minute;
  }
  if (type == "YYYY/MM/DD h") {
    return year + "/" + mouth + "/" + day + " " + hour + ":00";
  }
  if (type == "YYYY/MM/DD") {
    return year + "/" + mouth + "/" + day;
  }
  if (type == "MM/DD") {
    return mouth + "/" + day;
  }
  if (type == "h:m") {
    return hour + ":" + minute;
  }
  if (type == "MM/DD WEEK") {
    return mouth + "/" + day + " " + week;
  }

  // 通过 '年月日' 链接
  if (type == "YYYY年MM月DD日") {
    return year + "年" + mouth + "月" + day + "日";
  }
  if (type == "YYYY年MM月DD日 h:m") {
    return year + "年" + mouth + "月" + day + "日 " + hour + ":" + minute;
  }
};
